# from os import name
import pathlib
from queue import Queue
import time
import setting_get_set

cmds = setting_get_set.read_config("config.json")
settings = setting_get_set.read_config("settings.json")
probability_cmd_int = settings["probability_cmd_int"]
cmds_void = cmds["void"]

work_mode = ""
# work_mode = "combat_mode "

set_list_ket_config = [
    "default_modul",
    "dict_value_str_voice",
    "probability_cmd",
    "probability_cmd_titles",
    "probability_cmd_int",
    "probability_cmd_metka",
    "probability_cmd_folder",
    "probability_cmd_folder",
    "probability_cmd_start_sr",
    "name_separation",
    "func_separation_name",
    "kol_void_err",
    "tags_decoder_flag",
    "turning_message",
    "one_func",
    "meta_data",
    "value_print_separation_file_manager",
    "enabling_activation",
    "permission_check_speech",
    "buff_mess_speech_count",
    "buff_mess_comm_count",
    "blocking_update_flag",
    "message_blocking",
    "sr_err_permmusion_name_params",
    "count_sr_err_permmusion_name_value",
    "number_of_seconds_of_inactivity",
    "sleep_prohibition",
    "flag_sleep_core",
    "version",
    "rate",
    "pitch",
    "hidden_function",
    "temporary_files",
]


time_out_mess_start = 0
time_out_mess_len = 0
message_read = True

exit_set_config = True
say_expectatio = 10

kernel_start_time = time.time()
# time from the beginning of the system sleep
# время с начала проспания системы
time_of_last_action = kernel_start_time
# number of recognition errors for falling asleep
# количество ошибок распознавания для засыпания
exit_flag = False
# Запрет на завершение работы
no_exit = False
comuniction_str_api = ""
speech_recognition_str_api = ""
speech_recognition_str_api_one = ""
cmd_str_api = ""
tags_list_api = []
tags_dict_api = {}
tags_int_api = None

buff_list_mess_speech = {"mess": [], "data": []}
buff_list_mess_comm = {"mess": [], "data": []}

queue_message_thread = Queue()
queue_message_external_events = Queue()
stopwatch = Queue()
stream_speech = Queue()
stop_sr = Queue()
stop_sr.put("True")


way_modul_file = ""
decoder_tags_vs_str = ""
# os.path.dirname(os.path.abspath(__file__))
# file_project = '/media/doctor/disk/fileprogect/Jarvis_core/core'
path_core = str(pathlib.Path(__file__).parent.resolve())
path_core = path_core[0: path_core.rfind("/")]
way_egg = f"{path_core}/egg/"
way_egg_json = f"{path_core}/egg_json/"
path_bd = f"{path_core}/database/"
project_way = f"{path_core}"
protocol_file_dir = f"{project_way}protocol/"
# /media/doctor/disk/fileprogect/Jarvis_Core/protocol/
model_way = f"{path_bd}vosk-model-small-ru-0.15/"
model_mini_way = f"{path_bd}vosk-model-small-ru-0.15/"
way_home_dir = "/home/doctor/"
value_timer_sleep = 60
language = settings["language"]
default_modul = settings["default_modul"]
dict_value_str_voice = settings["dict_value_str_voice"]
# Предел нечёткого поиска распознование ключевых слов
probability_cmd = settings["probability_cmd"]
probability_cmd_const = 98
flexible_probability_cmd_cmds = True
count_error_word = 3
event_message = "cheek_message"
probability_cmd_titles = settings["probability_cmd_titles"]
# Предел нечёткого поиска распознование цифр
probability_cmd_int = settings["probability_cmd_int"]
probability_cmd_name = settings["probability_cmd_name"]
probability_cmd_metka = settings["probability_cmd_metka"]
probability_cmd_folder = settings["probability_cmd_folder"]
probability_cmd_start_sr = settings["probability_cmd_start_sr"]

"""разделение функций и меток при декодирование распознанных строк class Cmu_cmd
 Разделение == True"""
# Разобраться
name_separation = settings["name_separation"]
func_separation_name = settings["func_separation_name"]
kol_void_err = settings["kol_void_err"]
resualt_sr = settings["resualt_sr"]
tags_decoder_flag = settings["tags_decoder_flag"]

turning_message = settings["turning_message"]
one_func = settings["one_func"]
# Телеметрия вызова функций
meta_data = settings["meta_data"]
value_print_separation_file_manager = settings["value_print_separation_file_manager"]
# разрешение на активацию
enabling_activation = settings["enabling_activation"]
# разрешение проверку речи
permission_check_speech = settings["permission_check_speech"]
# increase_accuracy_factor = True
buff_mess_speech_count = settings["buff_mess_speech_count"]
buff_mess_comm_count = settings["buff_mess_comm_count"]
blocking_update_flag = settings["blocking_update_flag"]
message_blocking = settings["message_blocking"]
sr_err_permmusion_name_params = settings["sr_err_permmusion_name_params"]
count_sr_err_permmusion_name_value = settings["count_sr_err_permmusion_name_value"]
number_of_seconds_of_inactivity = settings["number_of_seconds_of_inactivity"]
sleep_prohibition = settings["sleep_prohibition"]
flag_sleep_core = settings["flag_sleep_core"]
version = settings["version"]
rate = settings["rate"]
pitch = settings["pitch"]
hidden_function = settings["hidden_function"]


json_log_info_func = {
    "label_bool": {True: "Функция с метокой", False: "Функция без метки"},
    "speech test": {
        True: "Разрешена проверка функции",
        False: "Запрещена проверка функции",
    },
    "activation_permission": {
        True: "Функция спрашивает разрешение на активацию",
        False: "Функция не спрашивает разрешение на активацию",
    },
    "function_classification": {
        "egg": "Функция принадлежит к классу яйцо",
        "core_utilities": "Функция принадлежит к утилиты ядра",
        "collection": "Функция является коллекцией",
    },
}

"dict_word_cmd_value"
temporary_files = settings["temporary_files"]
cmds_void = cmds["void"]
"""
def sort_len():
    for void in cmds_void:
        word_list= cmds_void[void]["word_list"]
        for i in range(len(word_list)):
            for j in range(len(word_list)-1):
                if len(word_list[j])<len(word_list[j+1]):
                    temp = word_list[j]
                    word_list[j] = word_list[j+1]
                    word_list[j+1] = temp
            print(word_list,"\n")

def sort_fuzz():
    for void in cmds_void:
        word_list= cmds_void[void]["word_list"]
        if 'dict_words' in word_list:
            word_list= word_list['dict_words']
            for i in range(len(word_list)):
                for j in range(len(word_list)-1):
                    if len(word_list[j])<len(word_list[j+1]):
                        temp = word_list[j]
                        word_list[j] = word_list[j+1]
                        word_list[j+1] = temp
                print(word_list,"\n")

sort_len()
"""
# print(cmds_void)
name_voice_help = cmds["name"][0]
